from solver.solver import Solver
import numpy as np
import pandas as pd
import random
import matplotlib.pyplot as plt
from matplotlib import rcParams

# todo

class GCSolver(Solver):
    def __init__(self, product_path="../data/产品信息.csv",
                 equip_path="../data/设备信息.csv",
                 route_path="../data/工艺路线.csv"):
        super().__init__(product_path, equip_path, route_path)
        self.product_num = len(self.data.products)
        self.product_map = {p.product_id: p for p in self.data.products}
        self.product_map_route_id = {p.product_id: p.route_id for p in self.data.products}

        self.route_num = len(self.data.routes)
        self.route_map = {r.route_id: r for r in self.data.routes}

        self.equ_num = len(self.data.equips)
        self.equ_type_id_map = {}
        self.equ_id_map = {equ.equip_name: equ for equ in self.data.equips}

    def init_population(self):
        pass

    def solve(self):
        optimalvalue = []
        optimalvariables = []

        # 两个决策变量的上下界，多维数组之间必须加逗号
        decisionVariables = [[-100, 100]] * 49
        # 精度
        delta = 0.001

        # 种群数量
        initialPopuSize = 100
        # 初始生成100个种群
        population = []
        for _ in initialPopuSize:
            one_person = [[] * self.equ_num]
            procedure_index = [0 for _ in range(self.product_num)]
            while True:
                x = random.randint(0, self.product_num - 1)

        print("polpupation.shape:", population.shape)

        population
        # 最大进化代数
        maxgeneration = 4000
        # 交叉概率
        prob = 0.8
        # 变异概率
        mutationprob = 0.5
        # 新生成的种群数量
        maxPopuSize = 30

        for generation in range(maxgeneration):
            # 对种群解码得到表现形
            print(generation)
            # print('the shape of decode:',decode.shape

            # 得到适应度值和累计概率值
            # 选择新的种群
            # 新种群交叉
            # 变异操作

            # 将父母和子女合并为新的种群
            # 最终解码
            # 适应度评估
            # 选出适应度最大的100个重新生成种群

            # 找到本轮中适应度最大的值

    def write_ans(self, ans_path):
        pass

